﻿@model Dotnet9.Web.ViewModels.Comments.CommentListViewModel
@inject HttpClient HttpClient

@{
    var comments = Model.Comments?.Where(x => x.ParentId == Model.ParentId).ToList();
}

<div id="comment-section" class="row">
    <div class="col-sm-7">
        <ul class="comments">
            @if (comments is { Count: > 0 })
            {
                @foreach (var comment in comments)
                {
                    <li class="comment" data-id="@comment.Id">
                        <div class="avatar">
                            <a href="javascript:void(0);">
                                <img src="~/images/avatar.jpg" width="55" height="55">
                            </a>
                        </div>
                        <div data-id="@comment.Id" class="comment-body">
                            <header>
                                <a href="javascript:void(0);" class="userlink">@comment.UserName</a> - <span class="pubdate">评论于 @comment.CreationTime</span>
                            </header>
                            <p>
                                @comment.Content
                            </p>
                            <footer>
                                <a class="reply-link" href="@comment.Id">回复</a>
                            </footer>
                        </div>

                        @{
                            var children = Model.Comments!.Where(x => x.ParentId == comment.Id).ToList();
                            if (children is { Count: > 0 })
                            {
                                <ul data-parentid="@comment.Id" class="replies">
                                    @await Html.PartialAsync("_CommentListPartial", Model with { ParentId = comment.Id })
                                </ul>
                            }
                        }

                    </li>
                }
            }
        </ul>
    </div>
</div>